home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / troubleshoot / ChoosePrinter.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  6KB  |  135 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import cups
  5. import gobject
  6. from timedops import TimedOperation
  7. from base import *
  8.  
  9. class ChoosePrinter(Question):
  10.     
  11.     def __init__(self, troubleshooter):
  12.         Question.__init__(self, troubleshooter, 'Choose printer')
  13.         page1 = self.initial_vbox(_('Choose Printer'), _("Please select the printer you are trying to use from the list below. If it does not appear in the list, select 'Not listed'."))
  14.         tv = gtk.TreeView()
  15.         name = gtk.TreeViewColumn(_('Name'), gtk.CellRendererText(), text = 0)
  16.         location = gtk.TreeViewColumn(_('Location'), gtk.CellRendererText(), text = 1)
  17.         info = gtk.TreeViewColumn(_('Information'), gtk.CellRendererText(), text = 2)
  18.         name.set_property('resizable', True)
  19.         location.set_property('resizable', True)
  20.         info.set_property('resizable', True)
  21.         tv.append_column(name)
  22.         tv.append_column(location)
  23.         tv.append_column(info)
  24.         tv.set_rules_hint(True)
  25.         sw = gtk.ScrolledWindow()
  26.         sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
  27.         sw.set_shadow_type(gtk.SHADOW_IN)
  28.         sw.add(tv)
  29.         page1.pack_start(sw, True, True, 0)
  30.         self.treeview = tv
  31.         troubleshooter.new_page(page1, self)
  32.  
  33.     
  34.     def display(self):
  35.         model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
  36.         self.treeview.set_model(model)
  37.         iter = model.append(None)
  38.         model.set(iter, 0, _('Not listed'), 1, '', 2, '', 3, None)
  39.         parent = self.troubleshooter.get_window()
  40.         
  41.         try:
  42.             cups.setServer('')
  43.             c = self.timedop(cups.Connection, parent = parent).run()
  44.             dests = self.timedop(c.getDests, parent = parent).run()
  45.             printers = None
  46.             dests_list = []
  47.             for name, instance in dests.iteritems():
  48.                 dest = None
  49.                 if name == None:
  50.                     continue
  51.                 
  52.                 if instance != None:
  53.                     queue = '%s/%s' % (name, instance)
  54.                 else:
  55.                     queue = name
  56.                 if printers == None:
  57.                     printers = self.timedop(c.getPrinters, parent = parent).run()
  58.                 
  59.                 if not printers.has_key(name):
  60.                     info = _('Unknown')
  61.                     location = _('Unknown')
  62.                 else:
  63.                     printer = printers[name]
  64.                     info = printer.get('printer-info', _('Unknown'))
  65.                     location = printer.get('printer-location', _('Unknown'))
  66.                 dests_list.append((queue, location, info, dest))
  67.             
  68.             dests_list.sort((lambda x, y: cmp(x[0], y[0])))
  69.             for queue, location, info, dest in dests_list:
  70.                 iter = model.append(None)
  71.                 model.set(iter, 0, queue, 1, location, 2, info, 3, dest)
  72.         except cups.HTTPError:
  73.             pass
  74.         except cups.IPPError:
  75.             pass
  76.         except RuntimeError:
  77.             pass
  78.  
  79.         return True
  80.  
  81.     
  82.     def connect_signals(self, handler):
  83.         self.signal_id = self.treeview.connect('cursor-changed', handler)
  84.  
  85.     
  86.     def disconnect_signals(self):
  87.         self.treeview.disconnect(self.signal_id)
  88.  
  89.     
  90.     def can_click_forward(self):
  91.         (model, iter) = self.treeview.get_selection().get_selected()
  92.         if iter == None:
  93.             return False
  94.         return True
  95.  
  96.     
  97.     def collect_answer(self):
  98.         (model, iter) = self.treeview.get_selection().get_selected()
  99.         dest = model.get_value(iter, 3)
  100.         if dest == None:
  101.             
  102.             class enum_dests:
  103.                 
  104.                 def __init__(self, model):
  105.                     self.dests = []
  106.                     model.foreach(self.each, None)
  107.  
  108.                 
  109.                 def each(self, model, path, iter, user_data):
  110.                     dest = model.get_value(iter, 3)
  111.                     if dest:
  112.                         self.dests.append((dest.name, dest.instance))
  113.                     
  114.  
  115.  
  116.             return {
  117.                 'cups_queue_listed': False,
  118.                 'cups_dests_available': enum_dests(model).dests }
  119.         return {
  120.             'cups_queue_listed': True,
  121.             'cups_dest': dest,
  122.             'cups_queue': dest.name,
  123.             'cups_instance': dest.instance }
  124.  
  125.     
  126.     def cancel_operation(self):
  127.         self.op.cancel()
  128.  
  129.     
  130.     def timedop(self, *args, **kwargs):
  131.         self.op = TimedOperation(*args, **kwargs)
  132.         return self.op
  133.  
  134.  
  135.